<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'display';
if($_RQ['op']=='display'){
	$return=array();
	$open=core_setting('open');
	$return['item']=array_fields(array('appid','secret','token','key'),$open);
	if(!$return['item']){
		$return['item']['token']=random(32);
		$return['item']['key']=random(43);
	}
	$return['host']=$_SERVER['HTTP_HOST'];//发起页域名，网页开发域名
	$return['test_url']=$_AR['siteroot'].'api/wx_open.php?op=test';;//发起授权页的体验url
	$return['get_url']=$_AR['siteroot'].'api/wx_open.php?op=ticket';//授权事件接收url
	$return['receive_url']=$_AR['siteroot'].'api/wxapi.php?appid=/$APPID$';//公众号消息与事件接受URL
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'开放平台',
		'tabs'=>array(
			'0'=>array('op'=>'display','title'=>'微信开放平台接口设置'),
		),
		'edits'=>array(
			array('title'=>'开放平台参数（从开放平台获取）','list'=>array(
				array('type'=>'tip','title'=>'1、移步微信第三方平台--》第三方平台--》创建第三方平台；2、全网发布；3、添加本服务器IP到白名单（必须添加到<red>白名单</red>，否则会很多异常！）'),
				array('type'=>'string','title'=>'APPID','name'=>'appid', 'help'=>'微信开放平台注册且审核通过后可以获取到AppId' ),
				array('type'=>'string','title'=>'APPSecret','name'=>'secret', 'help'=>'微信开放平台注册且审核通过后可以获取到AppSecret' ),
				array('type'=>'string','title'=>'公众号消息校验Token','name'=>'token','help'=>'公众号消息校验Token，3-32位' ),
				array('type'=>'string','title'=>'公众号消息加解密Key','name'=>'key','help'=>'公众号消息加解密Key，43位' ),
			)),array('title'=>'系统参数（填往开放平台）','list'=>array(
				array('type'=>'copy','title'=>'登录授权的发起页域名','name'=>'host','read'=>true,'tovalue'=>'pagedata','help'=>'' ),
				array('type'=>'copy','title'=>'发起授权页的体验URL','name'=>'test_url','read'=>true,'tovalue'=>'pagedata', 'help'=>'' ),
				array('type'=>'copy','title'=>'授权事件接受URL','name'=>'get_url','read'=>true,'tovalue'=>'pagedata','help'=>'' ),
				array('type'=>'copy','title'=>'公众号消息与事件接受URL','name'=>'receive_url','read'=>true,'tovalue'=>'pagedata','help'=>'' ),
				array('type'=>'copy','title'=>'网页开发域名','name'=>'host','read'=>true,'tovalue'=>'pagedata','help'=>'' ),
			)),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array('appid','secret','token','key'),$post);
	$open=core_setting('open');
	if($open){
		$data=array_merge($open,$data);
	}
	$setting=array('key'=>'open','value'=>ijson_encode($data));
	pdo_insert('core_settings',$setting,true);
	exi('设置成功！');
}
